<script charset="UTF-8">
    $('#shiro_role_list_add').click(function () {
        var d = sy.dialog({
            title: '新增角色',
            href: '${ctxPath}/shiro/role/form',
            buttons: [{
                text: '新增',
                iconCls: 'icon-add',
                handler: function () {
                    $.messager.progress();
                    $('#shiro_role_form_form').form('submit', {
                        url: '${ctxPath}/shiro/role/add',
                        onSubmit: function () {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function (result) {
                            var result = eval('(' + result + ')');
                            if (result.success) {
                                $('#shiro_role_list_grid').datagrid('reload');
                                $.messager.show({
                                    title: '提示',
                                    msg: result.msg,
                                    showType: 'show'
                                });
                                d.dialog('destroy');
                            } else {
                                $.messager.alert('提示', result.msg, 'error');
                            }
                            $.messager.progress('close');
                        }
                    });
                }
            }]
        });
    });
    $('#shiro_role_list_edit').click(function () {
        var row = $('#shiro_role_list_grid').datagrid('getSelected');
        if (row) {
            var d = sy.dialog({
                title: '修改角色',
                href: '${ctxPath}/shiro/role/form?id=' + row.id,
                buttons: [{
                    text: '编辑',
                    iconCls: 'icon-edit',
                    handler: function () {
                        $.messager.progress();
                        $('#shiro_role_form_form').form('submit', {
                            url: '${ctxPath}/shiro/role/edit',
                            onSubmit: function () {
                                var isValid = $(this).form('validate');
                                if (!isValid) {
                                    $.messager.progress('close');
                                }
                                return isValid;
                            },
                            success: function (result) {
                                var result = eval('(' + result + ')');
                                if (result.success) {
                                    $('#shiro_role_list_grid').datagrid('reload');
                                    $.messager.show({
                                        title: '提示',
                                        msg: result.msg,
                                        showType: 'show'
                                    });
                                    d.dialog('destroy');
                                } else {
                                    $.messager.alert('提示', result.msg, 'error');
                                }
                                $.messager.progress('close');
                            }
                        });
                    }
                }]
            });
        }
    });
    $('#shiro_role_list_remove').click(function () {
        var row = $('#shiro_role_list_grid').datagrid('getSelected');
        if (row) {
            $.messager.confirm('询问', '您确定要删除 [' + row.name + '] ？', function (r) {
                if (r) {
                    $.messager.progress();
                    $.post('${ctxPath}/shiro/role/remove/' + row.id, function (result) {
                        if (result.success) {
                            $('#shiro_role_list_grid').datagrid('reload');
                            $.messager.show({
                                title: '提示',
                                msg: '[' + row.name + '] ' + result.msg,
                                showType: 'show'
                            });
                        } else {
                            $.messager.alert('提示', '[' + row.name + '] 删除失败！', 'error');
                        }
                        $.messager.progress('close');
                    }, 'json');
                }
            });
        }
    });
</script>
<div id="shiro_role_list_gridToolbar">
    @if(shiro.hasPermission("shiro:role:add")){
    <a id="shiro_role_list_add" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新增</a>
    @}
    @if(shiro.hasPermission("shiro:role:edit")){
    <a id="shiro_role_list_edit" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
    @}
    @if(shiro.hasPermission("shiro:role:remove")){
    <a id="shiro_role_list_remove" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
    @}
</div>
<table id="shiro_role_list_grid" class="easyui-datagrid"
       data-options="url:'${ctxPath}/shiro/role/list',fit:true,border:false,toolbar:'#shiro_role_list_gridToolbar',fitColumns:true,singleSelect:true
                    ,pagination:true">
    <thead>
    <tr>
        <th data-options="field:'id',hidden:true">ID</th>
        <th data-options="field:'name'">角色名称</th>
        <th data-options="field:'code'">角色编码</th>
    </tr>
    </thead>
</table>